//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类.demo20AND40;

public class demo34 {
    public demo34() {
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1};
        int target = 1;
        int[] a = searchRange(nums, target);

        for(int j : a) {
            System.out.println(j);
        }

    }

    public static int[] searchRange(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        int mid = 0;

        while(left <= right) {
            mid = left + (right - left) / 2;
            if (nums[mid] == target) {
                break;
            }

            if (nums[mid] < target) {
                left = mid + 1;
            } else if (nums[mid] > target) {
                right = mid - 1;
            }
        }

        if (mid >= 0 && mid < nums.length && nums[mid] == target) {
            left = mid;

            for(right = mid; left - 1 >= 0 && nums[left - 1] == target; --left) {
            }

            while(right + 1 < nums.length && nums[right + 1] == target) {
                ++right;
            }

            return new int[]{left, right};
        } else {
            return new int[]{-1, -1};
        }
    }
}
